<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Hard
  </div>
  <div>
   <h1 class="question_title">
    135. Candy
   </h1>
   <p>
    There are
    <em>
     N
    </em>
    children standing in a line. Each child is assigned a rating value.
   </p>
   <p>
    You are giving candies to these children subjected to the following requirements:
   </p>
   <ul>
    <li>
     Each child must have at least one candy.
    </li>
    <li>
     Children with a higher rating get more candies than their neighbors.
    </li>
   </ul>
   <p>
    What is the minimum candies you must give?
   </p>
   <p>
    <strong>
     Example 1:
    </strong>
   </p>
   <pre>
<strong>Input:</strong> [1,0,2]
<strong>Output:</strong> 5
<strong>Explanation:</strong> You can allocate to the first, second and third child with 2, 1, 2 candies respectively.
</pre>
   <p>
    <strong>
     Example 2:
    </strong>
   </p>
   <pre>
<strong>Input:</strong> [1,2,2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> You can allocate to the first, second and third child with 1, 2, 1 candies respectively.
             The third child gets 1 candy because it satisfies the above two conditions.
</pre>
  </div>
  <div>
   <h1 class="question_title">
    135. 分发糖果
   </h1>
   <p>
    老师想给孩子们分发糖果，有
    <em>
     N
    </em>
    &nbsp;个孩子站成了一条直线，老师会根据每个孩子的表现，预先给他们评分。
   </p>
   <p>
    你需要按照以下要求，帮助老师给这些孩子分发糖果：
   </p>
   <ul>
    <li>
     每个孩子至少分配到 1 个糖果。
    </li>
    <li>
     相邻的孩子中，评分高的孩子必须获得更多的糖果。
    </li>
   </ul>
   <p>
    那么这样下来，老师至少需要准备多少颗糖果呢？
   </p>
   <p>
    <strong>
     示例&nbsp;1:
    </strong>
   </p>
   <pre><strong>输入:</strong> [1,0,2]
<strong>输出:</strong> 5
<strong>解释:</strong> 你可以分别给这三个孩子分发 2、1、2 颗糖果。
</pre>
   <p>
    <strong>
     示例&nbsp;2:
    </strong>
   </p>
   <pre><strong>输入:</strong> [1,2,2]
<strong>输出:</strong> 4
<strong>解释:</strong> 你可以分别给这三个孩子分发 1、2、1 颗糖果。
     第三个孩子只得到 1 颗糖果，这已满足上述两个条件。</pre>
  </div>
 </body>
</html>